package sv.gob.mh.dgii.model;

// Generated Dec 12, 2007 3:08:52 PM by Hibernate Tools 3.2.0.CR1

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import sv.gob.mh.dgii.common.Utils;

/**
 * TbMunicipio generated by hbm2java
 */
@Entity
@Table(name = "TB_MUNICIPIO", schema = "CATALOGOS")
public class TbMunicipio implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private TbMunicipioId id;
	private TbDepartamento tbDepartamento;
	private String cusuario;
	private String dmunicipio;
	private Integer bdesplegable;
	private Integer bstatus;
	private Date fhingreso;
	private Set<RcRuc> rcRucs = new HashSet<RcRuc>(0);
	private Set<RcDomicilio> rcDomicilios = new HashSet<RcDomicilio>(0);
        
	public TbMunicipio() {
	}

	public TbMunicipio(TbMunicipioId id, TbDepartamento tbDepartamento,
			String cusuario, String dmunicipio, Integer bdesplegable,
			Integer bstatus) {
		this.id = id;
		this.tbDepartamento = tbDepartamento;
		this.cusuario = cusuario;
		this.dmunicipio = dmunicipio;
		this.bdesplegable = bdesplegable;
		this.bstatus = bstatus;
	}

	public TbMunicipio(TbMunicipioId id, TbDepartamento tbDepartamento,
			String cusuario, String dmunicipio, Integer bdesplegable,
			Integer bstatus, Date fhingreso, Set<RcRuc> rcRucs,
			Set<RcDomicilio> rcDomicilios) {
		this.id = id;
		this.tbDepartamento = tbDepartamento;
		this.cusuario = cusuario;
		this.dmunicipio = dmunicipio;
		this.bdesplegable = bdesplegable;
		this.bstatus = bstatus;
		this.fhingreso = fhingreso;
		this.rcRucs = rcRucs;
		this.rcDomicilios = rcDomicilios;
	}

	@EmbeddedId
	@AttributeOverrides( {
			@AttributeOverride(name = "cdepartamento", column = @Column(name = "C_DEPARTAMENTO", nullable = false, length = 2)),
			@AttributeOverride(name = "cmunicipio", column = @Column(name = "C_MUNICIPIO", nullable = false, length = 2)) })
	public TbMunicipioId getId() {
		return this.id;
	}

	public void setId(TbMunicipioId id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "C_DEPARTAMENTO", nullable = false, insertable = false, updatable = false)
	public TbDepartamento getTbDepartamento() {
		return this.tbDepartamento;
	}

	public void setTbDepartamento(TbDepartamento tbDepartamento) {
		this.tbDepartamento = tbDepartamento;
	}

	@Column(name = "C_USUARIO", nullable = false, length = 30)
	public String getCusuario() {
		return this.cusuario;
	}

	public void setCusuario(String cusuario) {
		this.cusuario = cusuario;
	}

	@Column(name = "D_MUNICIPIO", nullable = false, length = 50)
	public String getDmunicipio() {
		return this.dmunicipio;
	}

	public void setDmunicipio(String dmunicipio) {
		this.dmunicipio = dmunicipio;
	}

	@Column(name = "B_DESPLEGABLE", nullable = false, precision = 1, scale = 0)
	public Integer getBdesplegable() {
		return this.bdesplegable;
	}

	public void setBdesplegable(Integer bdesplegable) {
		this.bdesplegable = bdesplegable;
	}

	@Column(name = "B_STATUS", nullable = false, precision = 1, scale = 0)
	public Integer getBstatus() {
		return this.bstatus;
	}

	public void setBstatus(Integer bstatus) {
		this.bstatus = bstatus;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "FH_INGRESO", length = 7)
	public Date getFhingreso() {
		return this.fhingreso;
	}

	public void setFhingreso(Date fhingreso) {
		this.fhingreso = fhingreso;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "tbMunicipio")
	public Set<RcRuc> getRcRucs() {
		return this.rcRucs;
	}

	public void setRcRucs(Set<RcRuc> rcRucs) {
		this.rcRucs = rcRucs;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "tbMunicipio")
	public Set<RcDomicilio> getRcDomicilios() {
		return this.rcDomicilios;
	}

	public void setRcDomicilios(Set<RcDomicilio> rcDomicilios) {
		this.rcDomicilios = rcDomicilios;
	}

    @Transient
    public String getPseudoId() {
        if(!Utils.isNullOrEmpty(id)){
            return id.getCdepartamento()+"|"+id.getCmunicipio();
        }
        return "";        
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 61 * hash + (this.id != null ? this.id.hashCode() : 0);
        hash = 61 * hash + (this.tbDepartamento != null ? this.tbDepartamento.hashCode() : 0);
        hash = 61 * hash + (this.cusuario != null ? this.cusuario.hashCode() : 0);
        hash = 61 * hash + (this.dmunicipio != null ? this.dmunicipio.hashCode() : 0);
        hash = 61 * hash + (this.bdesplegable != null ? this.bdesplegable.hashCode() : 0);
        hash = 61 * hash + (this.bstatus != null ? this.bstatus.hashCode() : 0);
        hash = 61 * hash + (this.fhingreso != null ? this.fhingreso.hashCode() : 0);
        //hash = 61 * hash + (this.rcRucs != null ? this.rcRucs.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final TbMunicipio other = (TbMunicipio) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        if (this.tbDepartamento != other.tbDepartamento && (this.tbDepartamento == null || !this.tbDepartamento.equals(other.tbDepartamento))) {
            return false;
        }
        if ((this.cusuario == null) ? (other.cusuario != null) : !this.cusuario.equals(other.cusuario)) {
            return false;
        }
        if ((this.dmunicipio == null) ? (other.dmunicipio != null) : !this.dmunicipio.equals(other.dmunicipio)) {
            return false;
        }
        if (this.bdesplegable != other.bdesplegable && (this.bdesplegable == null || !this.bdesplegable.equals(other.bdesplegable))) {
            return false;
        }
        if (this.bstatus != other.bstatus && (this.bstatus == null || !this.bstatus.equals(other.bstatus))) {
            return false;
        }
        if (this.fhingreso != other.fhingreso && (this.fhingreso == null || !this.fhingreso.equals(other.fhingreso))) {
            return false;
        }        
        return true;
    }

    
    
    @Override
    public String toString() {
        return "TbMunicipio{" + "id=" + id + ", tbDepartamento=" + tbDepartamento + ", cusuario=" + cusuario + ", dmunicipio=" + dmunicipio + ", bdesplegable=" + bdesplegable + ", bstatus=" + bstatus + ", fhingreso=" + fhingreso + '}';
    }

    
    
        

}
